package com.attendcollatesys.excel.style;


import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.*;

/**
 * 处理成果物表的表格样式处理器
 */
public class AtDayDetailsStyleProcessor implements CellWriteHandler {

    private int count;

    public static void main(String[] args) {

    }

    @Override
    public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Head head, Integer columnIndex, Integer relativeRowIndex, Boolean isHead) {
        Sheet sheet = writeSheetHolder.getSheet();
        System.out.println(count);
        if(isHead){
            System.out.println("==="+count);
            Row row1 = sheet.getRow(0);
            row1.setHeightInPoints(20);
            Workbook workbook = sheet.getWorkbook();
            Font font = workbook.createFont();
            font.setBold(true);
            font.setFontName("微软雅黑");
            font.setFontHeightInPoints((short) 12);
            CellStyle style = workbook.createCellStyle();
            style.setFont(font);
            style.setFillPattern(FillPatternType.NO_FILL);
            style.setAlignment(HorizontalAlignment.CENTER);
            style.setVerticalAlignment(VerticalAlignment.CENTER);
            for (int i = 0; i < row.getLastCellNum(); i++) {
                Cell cell = row.getCell(i);
                if (cell != null) {
                    cell.setCellStyle(style);
                }
            }

        }
        count++;





    }
}
